/**
  ******************************************************************************
  * @file    nuc it.c
  * @brief   Interrupt Service Routines.
  ******************************************************************************
**/

#include "sys.h"
#include "osObjects.h"
#include "dataproc.h"

void SwTestInit(void);


OS_TCB         SwTest1TaskTCB;
CPU_STK        SwTest1TaskStk[TASK_TASK_SW_TEST_STK_SIZE];

OS_TCB         SwTest2TaskTCB;
CPU_STK        SwTest2TaskStk[TASK_TASK_SW_TEST_STK_SIZE];

OS_TCB         SwTest3TaskTCB;
CPU_STK        SwTest3TaskStk[TASK_TASK_SW_TEST_STK_SIZE];

uint8_t testBuff[8];
uint32_t SwCnt = 0;

/*
*********************************************************************************************************
*                                          sw
*
* Description : Create application tasks.
*
* Argument(s) : none
*
* Return(s)   : none
*
* Note(s)     : none.
*********************************************************************************************************
*/
void SwTestTask(void *argument)
{
    OS_ERR err;
    CPU_TS p_ts;
    
    SwTestInit();
    OSTaskSemSet(&SwTestTaskTCB, 1, &err);
    
    for(;;)
    {
        OSTaskSemPend (100,
        OS_OPT_PEND_BLOCKING,
        &p_ts,
        &err);
        Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff);
        Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff);
        Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff);
        Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff);
        Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff);
        OSTaskSemPost (&SwTest1TaskTCB,
        OS_OPT_POST_NO_SCHED,
        &err);
    }
}

void SwTest1(void *argument)
{
    OS_ERR err;
    CPU_TS p_ts;
    
    OSTaskSemSet(&SwTest1TaskTCB, 1, &err);
    
    for(;;)
    {
        OSTaskSemPend (100,
        OS_OPT_PEND_BLOCKING,
        &p_ts,
        &err);
        Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff);
        Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff);
        Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff);
        Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff);
        Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff);
        OSTaskSemPost (&SwTest2TaskTCB,
        OS_OPT_POST_NO_SCHED,
        &err);
    }
}

void SwTest2(void *argument)
{
    OS_ERR err;
    CPU_TS p_ts;
    
    OSTaskSemSet(&SwTest2TaskTCB, 1, &err);
    
    for(;;)
    {
        OSTaskSemPend (100,
        OS_OPT_PEND_BLOCKING,
        &p_ts,
        &err);
        Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff);
        Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff);
        Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff);
        Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff);
        Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff);
        OSTaskSemPost (&SwTest3TaskTCB,
        OS_OPT_POST_NO_SCHED,
        &err);
    }
}

void SwTest3(void *argument)
{
    OS_ERR err;
    CPU_TS p_ts;
    
    OSTaskSemSet(&SwTest3TaskTCB, 1, &err);
    
    for(;;)
    {
        OSTaskSemPend (100,
        OS_OPT_PEND_BLOCKING,
        &p_ts,
        &err);
        Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff);
        Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff);
        Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff);
        Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff);
        Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff); Uint16ToAscii(SwCnt++, 3, testBuff);
    }
}


void SwTestInit(void)
{
    OS_ERR err;
    //-----------------------------------------------------------------------------------------------------------------------------
    OSTaskCreate((OS_TCB      *)&SwTest1TaskTCB,            
                 (CPU_CHAR    *)"SW1 Task",
                 (OS_TASK_PTR  )SwTest1,
                 (void        *)0u,
                 (OS_PRIO      )TASK_TASK_SW_TEST_PRIO,
                 (CPU_STK     *)&SwTest1TaskStk[0],
                 (CPU_STK_SIZE )TASK_TASK_SW_TEST_STK_SIZE*10/100,
                 (CPU_STK_SIZE )TASK_TASK_SW_TEST_STK_SIZE,
                 (OS_MSG_QTY   )0u,
                 (OS_TICK      )0u,
                 (void        *)0u,
                 (OS_OPT       )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
                 (OS_ERR      *)&err);
    //-----------------------------------------------------------------------------------------------------------------------------
    OSTaskCreate((OS_TCB      *)&SwTest2TaskTCB,            
                 (CPU_CHAR    *)"SW2 Task",
                 (OS_TASK_PTR  )SwTest2,
                 (void        *)0u,
                 (OS_PRIO      )TASK_TASK_SW_TEST_PRIO,
                 (CPU_STK     *)&SwTest2TaskStk[0],
                 (CPU_STK_SIZE )TASK_TASK_SW_TEST_STK_SIZE*10/100,
                 (CPU_STK_SIZE )TASK_TASK_SW_TEST_STK_SIZE,
                 (OS_MSG_QTY   )0u,
                 (OS_TICK      )0u,
                 (void        *)0u,
                 (OS_OPT       )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
                 (OS_ERR      *)&err);
    //-----------------------------------------------------------------------------------------------------------------------------
    OSTaskCreate((OS_TCB      *)&SwTest3TaskTCB,            
                 (CPU_CHAR    *)"SW3 Task",
                 (OS_TASK_PTR  )SwTest3,
                 (void        *)0u,
                 (OS_PRIO      )TASK_TASK_SW_TEST_PRIO,
                 (CPU_STK     *)&SwTest3TaskStk[0],
                 (CPU_STK_SIZE )TASK_TASK_SW_TEST_STK_SIZE*10/100,
                 (CPU_STK_SIZE )TASK_TASK_SW_TEST_STK_SIZE,
                 (OS_MSG_QTY   )0u,
                 (OS_TICK      )0u,
                 (void        *)0u,
                 (OS_OPT       )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
                 (OS_ERR      *)&err);
}
